/*
 *      UnitManager.cpp
 *      
 *      Copyright 2009 Daniel Penney <bikedude880@paqsario.tastywaffle.org>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */


#include "UnitManager.hpp"


UnitManager::UnitManager()
{
	
}

UnitManager::~UnitManager()
{
	while( m_vUnits.size() > 0 )
	{
		if ( m_vUnits.back() != 0 ) {
			delete m_vUnits.back();
		}
		m_vUnits.pop_back();
	}
}
/**
 * Build a unit according to criteria passed to the function and call
 * AddUnit to push it onto the stack
 **/
void UnitManager::CreateUnit( enum e_unitID um_ID, enum e_unitDir um_Dir, int x, int y )
{
	Unit *temp = new Unit;

	temp->setUnitType( um_ID );
	temp->setUnitDir( um_Dir );
	temp->setUnitPos( x, y );
	
	AddUnit( temp );

	return;
}

void UnitManager::AddUnit( Unit* pUnit )
{
	m_vUnits.push_back( pUnit );
}

Unit* UnitManager::GetUnit( unsigned int iIndex )
{
	if ( iIndex < 0 || iIndex > m_vUnits.size() )
		return 0;

	return m_vUnits.at( iIndex );
}
